﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ue.Infrastructure;
using Ue.Infrastructure.RepositoryFramework;
using Ue.Infrastructure.DomainBase;

namespace Ue.Qcdz.Domain.Tags
{
    public class TagService
    {
        private static ITagRepository repository;

        static TagService()
        {
            TagService.repository = RepositoryFactory.GetRepository<ITagRepository, Tag>();
        }

        public static Tag GetTag(object tagKey)
        {
            return TagService.repository.FindBy(tagKey);
        }

        public static IList<Tag> GetTags()
        {
            return TagService.repository.FindAll();
        }
        public static IDataResult<Tag> GetTags(IDataQuery dataQuery)
        {
            return TagService.repository.FindBy(dataQuery);
        }

        public static void AddTag(Tag tag)
        {
            TagService.repository.Add(tag);
        }

        public static void RemoveTag(Tag tag)
        {
            TagService.repository.Remove(tag);
        }
        public static void RemoveTag(object tagKey)
        {
            Tag tag = TagService.repository.FindBy(tagKey);
            if (tag == null)
            {
                throw new ArgumentOutOfRangeException("tagKey");
            }

            TagService.repository.Remove(tag);
        }

        public static void UpdateTag(Tag tag)
        {
            TagService.repository[tag.Key] = tag;
        }
    }
}
